package com.tiantianyuegou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tiantianyuegou.R;
import com.tiantianyuegou.model.RedModel;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/2/15.
 */
public class MyRedPackageAdapter extends BaseAdapter {

    private Context context;
    private LayoutInflater inflater;

    private List<RedModel> listRed;

    public MyRedPackageAdapter() {

    }

    public MyRedPackageAdapter(Context context) {
        this.context = context;
        listRed = new ArrayList<>();
        inflater = LayoutInflater.from(context);
    }

    public void setData(List<RedModel> listRed) {
        this.listRed.clear();
        this.listRed.addAll(listRed);
    }

    @Override
    public int getCount() {
        return listRed.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder = null;
        String signed = "";
        if (view == null) {
            view = inflater.inflate(R.layout.item_list_guan, null);
            holder = new Holder();
            holder.text_red_num = (TextView) view.findViewById(R.id.text_guan_num);
            holder.text_operation = (TextView) view.findViewById(R.id.text_operation);
            holder.text_data = (TextView) view.findViewById(R.id.text_data);
            view.setTag(holder);
        } else {
            holder = (Holder) view.getTag();
        }

        if (listRed.get(i).getTbrType() != null && !"".equals(listRed.get(i).getTbrType())) {
            if ("1".equals(listRed.get(i).getTbrType())) {
                holder.text_operation.setText("抢红包获取");
                signed = "+";
                holder.text_red_num.setTextColor(context.getResources().getColor(R.color.textcolor_red));
                Double value= Double.valueOf(listRed.get(i).getTrCount());
                holder.text_red_num.setText(signed + new DecimalFormat("0.00").format(value));
            } else if ("2".equals(listRed.get(i).getTbrType())) {
                holder.text_operation.setText("订单支付");
                signed = "";
                holder.text_red_num.setTextColor(context.getResources().getColor(R.color.color_e1fd7409));
                Double value= Double.valueOf(listRed.get(i).getTrCount());
                holder.text_red_num.setText(signed + new DecimalFormat("0.00").format(value));
            } else if ("3".equals(listRed.get(i).getTbrType())) {
                holder.text_operation.setText("提现");
                signed = "";
                holder.text_red_num.setTextColor(context.getResources().getColor(R.color.color_e1fd7409));
                Double value= Double.valueOf(listRed.get(i).getTrCount());
                holder.text_red_num.setText(signed + new DecimalFormat("0.00").format(value));
            }
        } else if (listRed.get(i).getTrType() != null && !"".equals(listRed.get(i).getTrType())) {
            if ("1".equals(listRed.get(i).getTrType())) {
                holder.text_operation.setText("购物时获取");
                signed = "+";
                holder.text_red_num.setTextColor(context.getResources().getColor(R.color.textcolor_red));
                holder.text_red_num.setText(signed + listRed.get(i).getTrCount());
            } else if ("2".equals(listRed.get(i).getTrType())) {
                holder.text_operation.setText("抢红包");
                signed = "";
                holder.text_red_num.setTextColor(context.getResources().getColor(R.color.color_e1fd7409));
                holder.text_red_num.setText(signed + listRed.get(i).getTrCount());
            }
        } else if (listRed.get(i).getTbsType() != null && !"".equals(listRed.get(i).getTbsType())) {
            if ("1".equals(listRed.get(i).getTbsType())) {
                holder.text_operation.setText("会员返利");
                signed = "+";
                holder.text_red_num.setTextColor(context.getResources().getColor(R.color.textcolor_red));
                Double value= Double.valueOf(listRed.get(i).getTrCount());
                holder.text_red_num.setText(signed + new DecimalFormat("0.00").format(value));
            } else if ("2".equals(listRed.get(i).getTbsType())) {
                holder.text_operation.setText("订单交易");
                signed = "+";
                holder.text_red_num.setTextColor(context.getResources().getColor(R.color.color_e1fd7409));
                Double value= Double.valueOf(listRed.get(i).getTrCount());
                holder.text_red_num.setText(signed + new DecimalFormat("0.00").format(value));
            } else if ("3".equals(listRed.get(i).getTbsType())) {
                holder.text_operation.setText("提现");
                signed = "";
                holder.text_red_num.setTextColor(context.getResources().getColor(R.color.color_e1fd7409));
                Double value= Double.valueOf(listRed.get(i).getTrCount());
                holder.text_red_num.setText(signed + new DecimalFormat("0.00").format(value));
            } else if ("4".equals(listRed.get(i).getTbsType())) {
                holder.text_operation.setText("退款扣除");
                signed = "";
                holder.text_red_num.setTextColor(context.getResources().getColor(R.color.color_e1fd7409));
                Double value= Double.valueOf(listRed.get(i).getTrCount());
                holder.text_red_num.setText(signed + new DecimalFormat("0.00").format(value));
            }
        }
        holder.text_data.setText(listRed.get(i).getTrAddtime());
//        holder.text_red_num.setText(signed + listRed.get(i).getTrCount());
        return view;
    }

    class Holder {
        TextView text_red_num, text_operation, text_data, text_order;
    }
}
